<template>
  <div class="container">
    <div class="app-container">
      <el-button size="mini" type="primary" class="btn-add">添加权限</el-button>
      <el-table
        :data="tableData"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      >
        <el-table-column
          prop="name"
          label="名称"
        />
        <el-table-column
          prop="code"
          label="标识"
        />
        <el-table-column
          prop="description"
          label="描述"
        />
        <el-table-column
          label="操作"
        >
          <template v-slot="{row}">
            <el-button v-if="row.type === 1" type="text" size="mini" @click="add(row.id)">添加</el-button>
            <el-button type="text" size="mini">编辑</el-button>
            <el-button type="text" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { getPermissionList } from '@/api/permission'
import { transListToTree } from '@/utils'
export default {
  name: 'Permission',
  data() {
    return {
      tableData: []
    }
  },
  created() {
    this.getPermissionList()
  },
  methods: {
    async getPermissionList() {
      const res = await getPermissionList()
      this.tableData = transListToTree(res, 0)
    }
  }
}
</script>

<style lang="scss" scoped>
.btn-add {
    margin: 10px;
}
</style>
